from rest_framework import serializers
from .models import Users

class CustomUserSerializer(serializers.ModelSerializer):
    class Meta:
        model = Users
        fields = ['username', 'email', 'password']
        extra_kwargs = {
            'password': {'write_only': True},
            'is_active':{'default': False},
            'is_superuser':{'default': False},
        }

    def create(self, validated_data):
        user = Users.objects.create_user(
            username=validated_data['username'],
            email=validated_data['email'],
            password=validated_data['password'],
            is_active = False,
            is_superuser = False,
        )
        return user

class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = Users
        fields = ('username', 'email', 'is_active', 'is_superuser','ip_address','date_joined', 'last_login')